home *** CD-ROM | disk | FTP | other *** search
/ FishMarket 1.0 / FishMarket v1.0.iso / fishies / 326-350 / disk_348 / installlibs / installlibs.asm < prev    next >
Assembly Source File  |  1992-05-06  |  9KB  |  316 lines

  1. ;***************************************************************************
  2. ;            InstallLibs.asm - Jeff Glatt, dissidents
  3. ;
  4. ; Set your editor's TAB width to 3.
  5. ;
  6. ; PURPOSE:
  7. ; This program facilitates copying amiga, disk-based libraries to the LIBS
  8. ; drawer of a boot disk (i.e. greatly simplifies hard disk installation of
  9. ; custom libraries). A WB user can click on this program's icon to
  10. ; install the libraries. A CLI user can CD to the directory of this program,
  11. ; and run the program. The libraries that are copied are specified by
  12. ; altering variables in this program before assembling.
  13. ;
  14. ; REQUIREMENTS:
  15. ; The programmer must modify the block of NamePtrs to reflect the
  16. ; names of the libraries to copy. All of the libraries should be placed in
  17. ; the same drawer, and PathName should reflect that. This program should
  18. ; be placed in a drawer relative to DrawerName. (i.e. the program uses the
  19. ; exact path you specify, and does not hunt for the libs.)
  20. ; Libraries must not be > 32000 bytes in size.
  21. ;
  22. ; ASSEMBLING:
  23. ; assemble this file as Install.o
  24. ; link as follows:
  25. ; blink Install.o small.lib nodebug to InstallLibs
  26.  
  27.     ;C.A.P.E. assembler directives (delete these if using another asm)
  28.     ADDSYM
  29.     SMALLOBJ
  30.     OBJFILE    "rad:install.o"
  31.  
  32.  ;================= from small.lib or amiga.lib (Commodore ==============
  33.     XREF    _LVOWaitPort,_LVOGetMsg,_LVOReplyMsg
  34.     XREF    _LVOCloseLibrary,_LVOOldOpenLibrary
  35.     XREF    _LVODisplayAlert,_LVOCurrentDir,_LVOWrite,_LVORead,_LVOExamine
  36.     XREF    _LVOOpen,_LVOClose,_LVODelay,_LVOOutput,_LVOLock,_LVOUnLock
  37.     XREF    _LVOAllocMem,_LVOFreeMem
  38.  
  39. ThisTask            equ $114    ;AHA! Now we don't have to use UGLY, SLOW INCLUDES!!
  40. pr_CLI            equ $AC
  41. pr_MsgPort        equ $5C
  42. sm_ArgList        equ 36
  43. wa_Lock            equ 0
  44. TDNestCnt        equ 295
  45. MODE_NEWFILE    equ 1006
  46. MODE_OLDFILE    equ 1005
  47.  
  48.                 bra.s    StartUp
  49.                 CNOP    0,4
  50. CopyMsg        dc.b    'Copying '
  51. FileInfoBlock:        ;overwrite the beginning of our program to use as a File-
  52.                         ;InfoBlock since we can overwrite it safely and it is
  53.                         ;LONG-WORD aligned. Note: this is NOT self-modifying code.
  54.                         ;Let's see you do this in C or Modula2.
  55. DOSName        dc.b    'dos.library',0
  56. IntuiName    dc.b    'intuition.library',0
  57. NoMem            dc.b    'Not enough memory to do installation',0
  58.                 ds.b    30
  59.         CNOP    0,2
  60. StartUp:
  61.         moveq        #0,d4                    ;no mem
  62.         moveq        #0,d5                    ;initially, assume failure
  63.     ;---Get Exec library base
  64.         movea.l    $0004,a6
  65.         movea.l    a6,a4                    ;save SysBase
  66.     ;---get the address of our task
  67.         movea.l    ThisTask(a6),a3
  68.     ;---Open the DOS library
  69.         lea        DOSName(pc),a1
  70.         jsr        _LVOOldOpenLibrary(a6)
  71.         movea.l    d0,a5                    ;no error check because this is in ROM
  72.     ;---Open the Intuition library
  73.         lea        IntuiName(pc),a1
  74.         jsr        _LVOOldOpenLibrary(a6)
  75.         move.l    d0,d7                    ;ditto
  76.     ;---are we running as a son of Workbench? If not (i.e. CLI), exit
  77.         move.l    pr_CLI(a3),d0
  78.         beq.s        WB
  79.         suba.l    a3,a3
  80.         movea.l    a5,a6
  81.         jsr        _LVOOutput(a6)
  82.         move.l    d0,d6
  83.         bra.s        clii
  84.     ;---Wait for WB startup msg
  85. WB        lea        pr_MsgPort(a3),a0
  86.         jsr        _LVOWaitPort(a6)
  87.         lea        pr_MsgPort(a3),a0
  88.         jsr        _LVOGetMsg(a6)
  89.         movea.l    d0,a3                    ;WB msg
  90.         movea.l    a5,a6                    ;get DOSBase
  91.     ;---get the sm_ArgList list
  92.         move.l    sm_ArgList(a3),d0
  93.         beq.s        _ex
  94.         movea.l    d0,a0
  95.         move.l    (a0),d1
  96.         jsr        _LVOCurrentDir(a6)
  97.     ;---Open a CON window to serve as DOS output window
  98. _ex    lea        CONspec(pc),a0
  99.         move.l    a0,d1
  100.         moveq        #0,d2
  101.         move.w    #MODE_NEWFILE,d2
  102.         jsr        _LVOOpen(a6)
  103.         move.l    d0,d6
  104.     ;---Get a 32K buffer to load/copy libs
  105. clii    movea.l    a4,a6
  106.         moveq        #0,d1
  107.         moveq        #0,d0
  108.         move.w    #32000,d0
  109.         jsr        _LVOAllocMem(a6)
  110.         lea        NoMem(pc),a1
  111.         move.l    d0,d4
  112.         beq        dspMSG
  113.     ;---Setup for loop
  114.         movea.l    a5,a6
  115.         lea        NamePtrs(pc),a2
  116.         lea        FileInfoBlock(pc),a4
  117. ;=================== Copy libs (1 at a time) to LIBS: ================
  118. NEXT:
  119.     ;---Append the next library name to our PathName
  120.         move.l    (a2),d5
  121.         beq        AllDone        ;is this the final 0 LONG?
  122.         lea        PathName(pc),a0
  123.         bsr        MakeName
  124.     ;---Open the library
  125.         moveq        #0,d2
  126.         move.w    #MODE_OLDFILE,d2
  127.         jsr        _LVOOpen(a6)
  128.         move.l    d0,d5
  129.         beq.s        fail3
  130.     ;---Print which file we are copying
  131.         lea        CopyMsg(pc),a1
  132.         bsr        dsp_alert
  133.     ;---Lock it
  134.     ;    You know, I really think that AmigaDOS is an incredibly bad DOS.
  135.     ;    BCPL??? No one at CBM should ever say anything bad about MS-DOS. At
  136.     ;    least MS-DOS is well-documented. Why couldn't the file handle have an
  137.     ;    easy access to the lock for the file? Because it makes good sense.
  138.         move.l    a4,d1            ;I wish that they used an Addr Reg for passing
  139.                                     ;the string name. Ugh!
  140.         moveq        #-2,d2
  141.         jsr        _LVOLock(a6)
  142.         move.l    d0,d1
  143.         beq.s        fail3
  144.         move.l    d1,-(sp)
  145.     ;---Get the size of the lib, and read in the entire lib
  146.         move.l    a4,d2
  147.         jsr        _LVOExamine(a6)
  148.         move.l    (sp),d1
  149.         move.l    d0,(sp)
  150.         jsr        _LVOUnLock(a6)
  151.         move.l    (sp)+,d0
  152. fail3    beq.s        faill
  153.         move.l    124(a4),d3    ;filesize
  154.         move.l    d4,d2
  155.         move.l    d5,d1
  156.         jsr        _LVORead(a6)
  157.         sub.l        d3,d0
  158.         bne.s        faill
  159.         move.l    d5,d1
  160.         jsr        _LVOClose(a6)
  161.     ;---Copy our buffer (lib) to LIBS:
  162.         lea        SysName(pc),a0
  163.         move.l    (a2)+,d5
  164.         bsr        MakeName
  165.         moveq        #0,d2
  166.         move.w    #MODE_NEWFILE,d2
  167.         jsr        _LVOOpen(a6)
  168.         move.l    d0,d5
  169.         beq.s        faill
  170.         ;size still in d3
  171.         move.l    d4,d2
  172.         move.l    d5,d1
  173.         jsr        _LVOWrite(a6)
  174.         sub.l        d3,d0
  175.         bne.s        faill
  176.         move.l    d5,d1
  177.         jsr        _LVOClose(a6)
  178.         bra        NEXT
  179.     ;---Show Success or Failure message to user, then delay
  180. faill    move.l    d5,d1
  181.         beq.s        fail2
  182.         jsr        _LVOClose(a6)
  183. fail2    lea        Failure(pc),a1
  184.         moveq        #0,d5
  185.         bra.s        dspMSG
  186. AllDone:
  187.         lea        Success(pc),a1
  188.         moveq        #1,d5
  189. dspMSG:
  190.         bsr        dsp_alert
  191. ;================= EXIT ROUTINE =====================
  192.     ;---close the CON window if WB
  193.         move.l    a3,d0
  194.         beq.s        fmem
  195.         moveq        #127,d1
  196.         add.l        d1,d1
  197.         jsr        _LVODelay(a6)
  198.         move.l    d6,d1
  199.         beq.s        fmem
  200.         jsr        _LVOClose(a6)
  201.     ;---Free 32K buffer
  202. fmem    movea.l    $0004,a6
  203.         move.l    d4,d0
  204.         beq.s        exit
  205.         moveq        #0,d0
  206.         move.w    #32000,d0
  207.         movea.l    d4,a1
  208.         jsr        _LVOFreeMem(a6)
  209.     ;---close DOS library
  210. exit    movea.l    a5,a1
  211.         jsr        _LVOCloseLibrary(a6)
  212.     ;---Close Intuition
  213.         movea.l    d7,a1
  214.         jsr        _LVOCloseLibrary(a6)
  215.     ;---return the startup message to our parent
  216.         move.l    a3,d0
  217.         beq.s        ignore
  218.         addq.b    #1,TDNestCnt(a6)
  219.         movea.l    a3,a1
  220.         jsr        _LVOReplyMsg(a6)
  221.     ;---adjust for our DOS cmd buffer
  222. ignore:
  223.     ;---this rts sends us back to DOS (what a frightening prospect!)
  224.         move.l    d5,d0
  225.         rts
  226.  
  227. MakeName:
  228.         ;lib name in d5
  229.         movea.l    a4,a1
  230.         move.l    a1,d1            ;put in d1 for Open()
  231. pthn    move.b    (a0)+,(a1)+
  232.         bne.s        pthn
  233.         subq.l    #1,a1
  234.         movea.l    d5,a0
  235. libn    move.b    (a0)+,(a1)+
  236.         bne.s        libn
  237.         rts
  238.  
  239. ;This makes an alert message out of the passed string in a1
  240. ;and displays it in our CON window, or as an Alert. 80 chars MAX in string.
  241. ;Uses a6, d2, d3. IntuitionBase in d7, DOSBase in a5, CONwindowHandle in d6.
  242. dsp_alert:
  243.         suba.w    #100,sp        ;local buffer
  244.         movea.l    sp,a0
  245.         addq.l    #2,a0         ;for Alert, skip X pos
  246.         moveq        #20,d0
  247.         move.b    d0,(a0)+        ;y co-ordinate = 20
  248.         move.l    a0,d2            ;start of string for _LVOWrite
  249.   ;---copy passed string to buffer and get numOfChars
  250.         movea.l    a1,a6
  251.         moveq        #80-1,d0
  252. lens    move.b    (a6)+,(a0)+
  253.         Dbeq        d0,lens(pc)
  254.         subq.l    #1,a6
  255.         suba.l    a1,a6            ;numOfChars (not counting NULL)
  256.   ;---If our CON window open, write the msg there
  257.         move.l    d6,d1
  258.         beq.s        WBalert
  259.         moveq        #10,d0
  260.         move.b    d0,-(a0)
  261.         move.l    a6,d3
  262.         addq.l    #1,d3
  263.         movea.l    a5,a6
  264.         jsr        _LVOWrite(a6)
  265.         bra.s        frbf
  266.   ;---If no CON window, post an alert
  267. WBalert:
  268.         clr.b        (a0)            ;continuation byte = 0
  269.     ;---center the string by adjusting the x position
  270.         moveq        #80-1,d1        ;80 chars MAX
  271.         sub.l        a6,d1
  272.         bcc.s        aler
  273.         moveq        #1,d1
  274. aler    lsr.l        #1,d1
  275.         lsl.w        #3,d1
  276.         movea.l    d2,a0
  277.         subq.l    #3,a0
  278.         move.w    d1,(a0)        ;x co-ordinate = (numOfChars/2) * 8 (WORD)
  279.     ;---display the alert
  280.         moveq        #50,d1        ;Height
  281.         moveq        #0,d0            ;RECOVERY_ALERT
  282.         movea.l    d7,a6
  283.         jsr        _LVODisplayAlert(a6)
  284.         movea.l    a5,a6            ;make sure that we get DOSBase back
  285. frbf    adda.w    #100,sp
  286.         rts
  287.  
  288. ;================== MODIFY THESE VARIABLES ==============
  289.  
  290. NamePtrs        dc.l    ReqLib    ;change these to add or subtract libs
  291.                 dc.l    TextName
  292.                 dc.l    DisEdName
  293.                 dc.l    ILBMlib
  294.                 dc.l    ColorLib
  295.                 dc.l    0            ;table MUST end with a 0 LONG
  296.  
  297. ;These are the libraries I want to copy to the boot disk
  298. ReqLib        dc.b    'requester.library',0
  299. ILBMlib        dc.b    'ilbm.library',0
  300. ColorLib        dc.b    'color.library',0
  301. TextName        dc.b    'text_ed.library',0
  302. DisEdName    dc.b    'dised.library',0
  303.  
  304. ;This is where InstallLibs is supposed to find them. For example, I put all
  305. ;my libs in a drawer called "libs", and placed InstallLibs in this drawer's
  306. ;parent.
  307. PathName        dc.b    'libs/',0
  308.  
  309. ;==================== Don't touch this stuff ======================
  310.  
  311. SysName        dc.b    'libs:',0
  312. Success        dc.b    'installation successful',0
  313. Failure        dc.b    'installion failure',0
  314. CONspec        dc.b    'CON:10/10/500/125/InstallLibs',0
  315.  
  316.